package com.keyue.controller;


import com.keyue.common.annotation.AnonymousAccess;
import com.keyue.common.constant.ServerResult;
import com.keyue.domain.vo.admin.AdminDeptQueryVO;
import com.keyue.domain.vo.admin.AdminDeptVO;
import com.keyue.log.Log;
import com.keyue.service.admin.AdminDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @date 2019-03-25
 */
@RestController
@Api(tags = "系统：部门管理")
@RequestMapping("/keyue/admin/depts")
public class DeptController {

    @Resource
    private AdminDeptService deptService;


    @Log("查询部门")
    @ApiOperation("查询部门")
    @PostMapping(value = "/list_by_page")
    @AnonymousAccess
    public ServerResult listByPage(@RequestBody @Validated AdminDeptQueryVO queryVO) {
        return deptService.list(queryVO);
    }

    @Log("新增部门")
    @ApiOperation("新增部门")
    @PostMapping("/add")
    @AnonymousAccess
    public ServerResult add(@RequestBody @Validated AdminDeptVO deptVO) {
        return deptService.add(deptVO);
    }

    @Log("修改部门")
    @ApiOperation("修改部门")
    @PutMapping
    @AnonymousAccess
    public ServerResult edit(@RequestBody @Validated AdminDeptVO deptVO) {
        return deptService.edit(deptVO);
    }

    @Log("删除部门")
    @ApiOperation("删除部门")
    @DeleteMapping
    @AnonymousAccess
    public ServerResult delete(@RequestBody @Validated AdminDeptQueryVO queryVO) {
        return deptService.deleteById(queryVO);
    }
}